//在api/index.js对外暴露一个接口名requestGoodsList
//在这里引入这个接口，只要引入这个接口就可以去发送请求
import { requestGoodsList } from '@/api'
// 存储状态的仓库
const state = {
    searchGoodsList: []
}
// 修改state唯一手段
const mutations = {

    searchGoodsList(state, searchGoodsList) {
        state.searchGoodsList = searchGoodsList
    }
}
// 处理action 可以处理自己的业务逻辑，可以处理异步请求
const actions = {
    //通过函数去发送http请求
    async getGoodsList({ commit }, params) {
        //调用远程服务器上面的接口获取查询出来的商品信息数据
        let searchGoodsList = await requestGoodsList(params);
        if (searchGoodsList.data.code === 200) {
            //听过commit上下文将数据提交到mutations
            commit("searchGoodsList", searchGoodsList.data.data)
        }
    }
}

const getters = {}

export default {
    state, mutations, actions, getters
}